package cn.exrick.xboot.flow.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.exrick.xboot.flow.entity.FlowNodeHandler;
import cn.exrick.xboot.flow.mapper.FlowNodeHandlerMapper;
import cn.exrick.xboot.flow.service.IFlowNodeHandlerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zy
 * @since 2022-08-31
 */
@Service
@Transactional
public class FlowNodeHandlerServiceImpl extends ServiceImpl<FlowNodeHandlerMapper, FlowNodeHandler> implements IFlowNodeHandlerService {


    @Autowired
    private FlowNodeHandlerMapper flowNodeHandlerMapper;

    @Override
    public IPage<FlowNodeHandler> selectPage(Page<FlowNodeHandler> page, FlowNodeHandler flowNodeHandler) {
        QueryWrapper<FlowNodeHandler> query = Wrappers.query();
        QueryWrapper<FlowNodeHandler> entityWrapper = getEntityWrapper(query, flowNodeHandler);
        return flowNodeHandlerMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<FlowNodeHandler> selectList(FlowNodeHandler flowNodeHandler) {
        QueryWrapper<FlowNodeHandler> query = Wrappers.query();
        QueryWrapper<FlowNodeHandler> entityWrapper = getEntityWrapper(query, flowNodeHandler);
        return flowNodeHandlerMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<FlowNodeHandler> getEntityWrapper(QueryWrapper<FlowNodeHandler> entityWrapper, FlowNodeHandler flowNodeHandler) {

        return entityWrapper;
    }


    @Override
    public List<FlowNodeHandler> getFlowNodeHandlerOnUser(String nodeId,Integer level) {
        QueryWrapper<FlowNodeHandler> query = Wrappers.query();
        query.lambda().eq(FlowNodeHandler::getFlowNodeinfoId,nodeId)
                .ge(level!=null,FlowNodeHandler::getRoleLevel,level);
        List<FlowNodeHandler> flowNodeHandlers=flowNodeHandlerMapper.selectList(query);
        return flowNodeHandlers;
    }
}
